<template>
<div style="width:100%;height: 1210px;">
  <div style="width:95%;margin:0 auto;" class="box-content">
      <!-- 头部 -->
    <div class="box-top" style="display:flex">
      <div  style="width:40%" class='box-top-left'>
        <div class="daohang">
      <i style="font-size:20px;color:#999;line-height:60px;float: left;"  class="el-icon-s-home"></i>  
      <el-breadcrumb >
      <el-breadcrumb-item style="font-size:15px;color:#999; line-height:60px; margin-left:8px;display:block;float: left;" >首页 </el-breadcrumb-item>
      <i style="font-size:15px;line-height:63px;margin-left:-3px;float: left" class="el-icon-folder-opened"></i>  
      <el-breadcrumb-item style="font-size:15px;line-height:64px; margin-left:8px;display:block;float: left;">优惠管理</el-breadcrumb-item>
      <i style="font-size:15px;line-height:63px; margin-left:5px;float: left"   class="el-icon-folder-opened"></i>  
      <el-breadcrumb-item style="font-size:15px;line-height:64px; margin-left:8px;display:block;float: left;">添加等级</el-breadcrumb-item>
    </el-breadcrumb>
      </div>
    </div>
  </div>
  </div>
  <div class="middle">
    <i @click="back()" style="font-size:20px;font-weight:700;margin-left:70px;margin-top:10px" class="el-icon-arrow-left"></i>

    <div class="content">
      
        <el-form  :rules="rules" :model="ruleForm"  ref="ruleForm" label-width="100px" class="demo-ruleForm">

  <el-form-item label="等级名称" >
    <el-select  v-model="value" placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
  </el-form-item>
  <el-form-item label="升级条件" >
    <el-radio label="订单金额数量"></el-radio>
 </el-form-item>
 <el-form-item
 prop="name"
  >
  <el-input v-model="ruleForm.name" style="width:240px;height:15px;" ></el-input>
  </el-form-item>
  <el-form-item
 prop="region"
 label="折扣"
  >
  <el-input v-model="ruleForm.region" style="width:240px;height:15px;" ></el-input>
  </el-form-item>
  <el-form-item label="状态" prop="resource">
    <el-radio-group v-model="ruleForm.resource">
      <el-radio label="启用"></el-radio>
      <el-radio label="禁用"></el-radio>
    </el-radio-group>
  </el-form-item>
 
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>

      
    </div>
    </div>
  </div>
</template>

<script>
import {addgrade} from '../../api/index'

export default {
data(){
    return{
        rules: {
          name: [
            { required: true, message: '会员升级条件,不填写默认为不自动升级', trigger: 'blur' },
          ],
          region: [
            { required: true, message: '请输入0.1-10之间的数字,值为空代表不设置折扣', trigger: 'blur' }
          ],
        },
        options: [{
          value: 'lv.8',
          label: 'lv.8'
        }, {
          value: 'lv.9',
          label: 'lv.9',
        }, {
          value: 'lv.10',
          label: 'lv.10'
        },  ],
        value:'',
        ruleForm: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
       
    }
},
methods:{
    back(){
    this.$router.back(-1)
  },
  submitForm() {
    if(this.value!==''&&this.ruleForm.region!==''&&this.ruleForm.name!==''){
        let a={
        name:this.value,
        discount:this.ruleForm.region,
        condition:this.ruleForm.name,
        state:this.ruleForm.resource
    }   
    addgrade(a).then(res=>{
      this.$message({
          message: '添加成功',
          type: 'success'
        });
    })
    }

       
      },
      resetForm() {
        this.value=='';
        this.ruleForm.region=='';
        this.ruleForm.name==''
      }
    
}

}
</script>

<style lang="scss">
.content{
    width: 700px;
    height: 500px;
    // background: red;
    margin: 80px 65px ;
}
</style>